package com.svms.service.mapper;

import java.util.Date;

import com.svms.model.SvmsIndent;
import com.svms.service.vo.AddressVO;
import com.svms.service.vo.IndentVO;

public class IndentMapper {

	public static SvmsIndent serviceToDml(IndentVO indentVO) {

		SvmsIndent svmsIntend = new SvmsIndent();
		svmsIntend.setIndentId(Long.valueOf(indentVO.getIndentId()));
		svmsIntend.setIndentDate(indentVO.getIndentDate());
		svmsIntend.setInvoiceNumber(Long.valueOf(indentVO.getInvoiceNumber()));
		svmsIntend.setInvoiceDate(indentVO.getInvoiceDate());
		svmsIntend.setShopName(indentVO.getAddress().getName());
		svmsIntend.setShopAddress(indentVO.getAddress().getAddressLine1());
		svmsIntend.setShopTelephone(indentVO.getAddress().getPhone());
		svmsIntend.setAmount(Float.valueOf(indentVO.getAmount()));
		svmsIntend.setCreatedBy("Amar");
		svmsIntend.setApprovedBy(indentVO.getApprovalManager());
		svmsIntend.setCreateTime(new Date());
		svmsIntend.setUpdatedTime(new Date());
		return svmsIntend;
	}

	public static IndentVO dmlToService(SvmsIndent svmsIndent) {

		IndentVO indentVO = new IndentVO();

		AddressVO addressVO = new AddressVO();

		indentVO.setIndentId(String.valueOf(svmsIndent.getIndentId()));
		indentVO.setIndentDate(svmsIndent.getIndentDate());
		indentVO.setInvoiceNumber(String.valueOf(svmsIndent.getInvoiceNumber()));
		indentVO.setInvoiceDate(svmsIndent.getInvoiceDate());
		indentVO.setAmount(String.valueOf(svmsIndent.getAmount()));
		indentVO.setCreatedUser(svmsIndent.getCreatedBy());
		indentVO.setApprovalManager(svmsIndent.getApprovedBy());

		addressVO.setName(svmsIndent.getShopName());
		addressVO.setAddressLine1(svmsIndent.getShopAddress());
		addressVO.setPhone(svmsIndent.getShopTelephone());
		
		indentVO.setAddress(addressVO);
		
		return indentVO;

	}
}
